using System;
using System.Collections.Generic;
using System.Text;
using SampleUtility;
using System.Windows.Forms;
using System.Threading;

namespace ttg_internal.utils
{
    public class SampleUtility : Utility
    {
        private SampleViewer _viewer;
        private GlobalInfo _info;

        public SampleUtility()
            : base("Sample Utility", "An example of pipeline visualizer")
        {
            //nothing
        }

        public override string ToString()
        {
            return ExternalName + ": " + Description;
        }

        public override void Close()
        {
            _viewer.Close();
            _viewer.Dispose();
        }

        private void GuiThreadEntry()
        {
            _viewer = new SampleViewer(_info);
            Application.Run(_viewer);
        }

        private static void OnClick(Object sender, EventArgs args)
        {
            MessageBox.Show("Menu Item \"Click Me!\" has been clicked!");
        }

        public override void Init(UtilityProps props, UtilController controller, GlobalInfo info)
        {
            _info = info;
            //Creating GUI thread.
            Thread guiThread = new Thread(GuiThreadEntry);
            guiThread.Start();
            //Building menu.
            ActionMenuRecord test = controller.AddMenuRecord(new ActionMenuRecord("test", null));
            test.CreateChild("Click Me!", null).Handler = OnClick;
        }

        public override void Update(float step)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override bool IsActive()
        {
            return _viewer.Visible;
        }

        public override void ActivateOrDeActivate()
        {
            _viewer.Visible = !_viewer.Visible;
        }
    }
}
